define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {

            //用户id
            var uid = $("#uid").val()
            //记录ids
            var ids = $("#reids").val()

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    //index_url: 'user_card/index' + location.search,
                    index_url: 'user_card/index?uid='+uid+'&ids='+ids,
                    add_url: 'user_card/add',
                    // edit_url: 'user_card/edit',
                    del_url: 'user_card/del',
                    multi_url: 'user_card/multi',
                    table: 'user_card',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [

                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'c_id', title: '卡种',operate:false},
                        {field: 'c_price', title: '价格',operate:false},
                        {field: 'c_hours', title: '小时数',operate:false},
                        {field: 'd_number', title: __('D_number'),operate:false},
                        {field: 'nickname', title: '关联用户',operate:'like'},
                        {field: 'type', title:'类型', searchList: {"0":'兑换',"1":'购卡'}, formatter: Table.api.formatter.status,operate:false},
                        {field: 'status', title:'状态', searchList: {"0":'未兑换',"1":'已兑换',"2":'已兑换并且消费完'}, formatter: Table.api.formatter.status},
                        {field: 'd_time', title:__('D_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'c_time', title: __('C_time'),operate:false},
                        {field: 'less_hours', title: __('Less_hours'),operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                commonSearch:true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
